package com.jrh.dal;

import java.util.ArrayList;
import java.util.List;

import com.jrh.domain.entity.UserLike;

/**
 * 喜欢DAO
 * 
 * @author jasen.hsu.cn@gmail.com 2012-8-7 下午7:59:45
 */
public class UserLikeDao extends BaseDao<UserLike> {

    public UserLikeDao(){
        this.namespace = "jrh.single.userLike";
    }

    /**
     * 增加用户喜欢
     * 
     * @param userId
     * @param refId
     * @param refType
     */
    public void create(Long userId, Long refId, int refType) {
        UserLike userLike = new UserLike();
        userLike.setRefId(refId);
        userLike.setRefType(refType);
        userLike.setUserId(userId);
        this.create(userLike);
    }

    /**
     * 删除用户喜欢
     * 
     * @param userId
     * @param refId
     * @param refType
     */
    public void delete(Long userId, Long refId, int refType) {
        List<Long> refIds = new ArrayList<Long>();
        refIds.add(refId);
        this.delete(userId, refIds, refType);
    }

    /**
     * 删除用户喜欢
     * 
     * @param userId
     * @param refId
     * @param refType
     */
    public void delete(Long userId, List<Long> refIds, int refType) {
        UserLike userLike = new UserLike();
        userLike.setRefIds(refIds);
        userLike.setRefType(refType);
        userLike.setUserId(userId);
        sqlMapClientTemplate.delete(namespace + "." + "deleteByRefs", userLike);
    }

    public Integer countByRef(Long userId, Long refId, int refType) {
        UserLike userLike = new UserLike();
        userLike.setRefId(refId);
        userLike.setRefType(refType);
        userLike.setUserId(userId);
        return (Integer) sqlMapClientTemplate.queryForObject(namespace + "." + "countByRef", userLike);
    }

    /**
     * 增加产品喜欢数量
     * 
     * @param productId
     */
    public void addProductLike(Long productId) {
        sqlMapClientTemplate.update(namespace + "." + "addProductLike", productId);
    }

    /**
     * 增加品牌喜欢数量
     * 
     * @param brandId
     */
    public void addBrandLike(Long brandId) {
        sqlMapClientTemplate.update(namespace + "." + "addBrandLike", brandId);
    }

    /**
     * 增加美图集喜欢数量
     * 
     * @param atlasId
     */
    public void addAtlasLike(Long atlasId) {
        sqlMapClientTemplate.update(namespace + "." + "addAtlasLike", atlasId);
    }

    /**
     * 增加样板间喜欢数量
     * 
     * @param showroomId
     */
    public void addShowroomLike(Long showroomId) {
        sqlMapClientTemplate.update(namespace + "." + "addShowroomLike", showroomId);
    }

    /**
     * 用户喜欢所有数量
     * 
     * @param userId
     * @return
     */
    public Integer getUserlikeAllNum(Long userId) {
        return (Integer) sqlMapClientTemplate.queryForObject(namespace + "." + "userlikeAll_count", userId);
    }

}
